#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   BOOT_SessionControl_0x10_test.py
@Time    :   2025/03/20 13:31:28
@Author  :   YangLiang 
@Version :   1.0
@Contact :   yangl@genvict.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

from pytest_assume.plugin import assume

import pytest
import logging
import time
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True


sessionControl = [  
    ("10 01", "50 01 00 32 01 F4"),             # 默认会话
    ("10 03", "50 03 00 32 01 F4"),             # 扩展会话
    ("10 02", "50 02 00 32 01 F4"),             # 编程会话
    ("10 81", ""),                              # 默认会话抑制响应
    ("10 83", ""),                              # 编程会话抑制响应
    ("10 82", ""),                      # 编程会话抑制响应尝试
    ("10 01 00", "7F 10 13"),          # 带合法参数
    ("10 03 01", "7F 10 13")                    # 带有效会话参数
]

sessionControl_NRC13 = [    
    ("10", "7F 10 13"),                         # 缺失子功能
    ("10 01 FF", "7F 10 13"),                   # 01带非法参数
    ("10 02 06", "7F 10 13"),                   # 02带非法参数
    ("10 03 10", "7F 10 13"),                   # 03带非法参数
    ("10 81 FF", "7F 10 13"),                   # 抑制01带非法参数
    ("10 83 10", "7F 10 13"),                   # 抑制03带非法参数
    ("10 82 00", "7F 10 13"),                   # 02子功能抑制响应尝试
    ("10 01 00 01", "7F 10 13"),                # 默认会话多参数
    ("10 03 02", "7F 10 13"),                   # 编程会话带非法切换参数
    ("10 03 FF FF", "7F 10 13")                 # 编程会话超长参数
]

sessionControl_NRC12 = [    
    ("10 00", "7F 10 12"),                      # 无效子功能0x00
    ("10 05", "7F 10 12"),                      # 未定义子功能0x05
    ("10 84", "7F 10 12"),                      # 无效抑制子功能0x84
    ("10 06", "7F 10 12"),                      # 未定义子功能0x06
    ("10 FF", "7F 10 12")                       # 保留子功能0xFF
]


'''物理寻址测试用例'''
class Test_BOOT_SessionControl_Phy(object):

    @allure.severity('normal')
    @allure.story('物理寻址会话管理')
    @allure.title('重复会话切换测试 [1001 → 1003] - 物理寻址')
    @allure.description('验证默认会话与编程会话的5次循环切换流程,测试系统在物理寻址模式下的会话稳定性')
    def test_sessionSwitch1_Phy(self, action, Driver):
        iStep = 1
        for i in range(5):
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01 00 32 01 F4", 0, iStep, False)
            time.sleep(1)
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False)

    @allure.severity('normal')
    @allure.title('物理寻址会话切换测试 [1001 → 1003 → 1101]')
    @allure.description('''验证三级会话切换流程:1. 默认会话(1001) → 编程会话(1003) 2. 尝试在编程会话下进入诊断会话(1101) 3. 检查NRC33的预期响应''')
    def test_sessionSwitch2_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01 00 32 01 F4", 0, iStep, False)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "11 01", "51 01", 0, iStep, False)

    @allure.severity('normal')
    @allure.title('物理寻址多级会话切换测试 [1003 → 1002 → 1103 → 1101]')
    @allure.description('''验证四级会话切换流程:1. 默认会话(1001) → 编程会话(1003) 2. 编程会话下尝试进入编程会话(1103) 3. 检查NRC33的安全访问拒绝响应 4. 验证返回默认会话(01101)的正响应''')
    def test_sessionSwitch3_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03 00 32 01 F4", 0, iStep, False)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "11 03", "7F 11 12", 0, iStep, False)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "11 01", "51 01", 0, iStep, False)

    @allure.severity('normal')
    @allure.title('物理寻址复合场景测试 [1003 → 1002 → 重启 → 重复前述步骤3次]')
    @allure.description('''验证包含电源重启的完整会话流程:1. 编程会话(1003) → 编程会话(1002)2. 执行MRR硬件重启操作3. 等待系统重新初始化(4秒)4. 验证诊断服务0x22F186的正响应''')
    def test_sessionSwitch4_Phy(self, action, Driver):
        iStep = 1
        for i in range(3):
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01 00 32 01 F4", 0, iStep, False)
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False)
            time.sleep(0.5)
            iStep = Driver['CAN'].restartETC_Power(Driver,iStep)
            with allure.step(f'Step{iStep}:wait 3s'): # type: ignore
                time.sleep(4)
                iStep += 1
            # iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "22 F1 86", "62 F1 86 01", 0, iStep, False)

    ids = [f"Request {req}" for req, resp in sessionControl]
    @allure.severity('normal')
    @allure.title('物理寻址默认会话测试')
    @allure.description('验证物理寻址模式默认会话(0x01)测试')
    @pytest.mark.parametrize('req,resp', sessionControl, ids=ids)
    def test_sessionControl_Default_Phy(self, action,  Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False)

    
    ids = [f"Request {req}" for req, resp in sessionControl]
    @allure.severity('normal')
    @allure.title('物理寻址编程会话测试')
    @allure.description('验证物理寻址模式编程会话(0x02)测试')
    @pytest.mark.parametrize('req,resp', sessionControl, ids=ids)
    def test_sessionControl_Programming_Phy(self, action,  Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = [f"Request {req}" for req, resp in sessionControl]
    @allure.severity('normal')
    @allure.title('物理寻址扩展会话测试')
    @allure.description('验证物理寻址模式扩展会话(0x03)测试')
    @pytest.mark.parametrize('req,resp', sessionControl, ids=ids)
    def test_sessionControl_Extended_Phy(self, action,  Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False)


    ids = [f"Request {req}" for req, resp in sessionControl_NRC13]
    @allure.severity('normal')
    @allure.title('物理寻址默认会话测试NRC13')
    @allure.description('验证物理寻址模式默认会话(0x01)下NRC13')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC13, ids=ids)
    def test_sessionControl_NRC13_Default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False)

    ids = [f"Request {req}" for req, resp in sessionControl_NRC13]
    @allure.severity('normal')
    @allure.title('物理寻址编程会话测试NRC13')
    @allure.description('验证物理寻址模式编程会话(0x02)下NRC13')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC13, ids=ids)
    def test_sessionControl_NRC13_Programming_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = [f"Request {req}" for req, resp in sessionControl_NRC13]
    @allure.severity('normal')
    @allure.title('物理寻址扩展会话测试NRC13')
    @allure.description('验证物理寻址模式扩展会话(0x03)下NRC13')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC13, ids=ids)
    def test_sessionControl_NRC13_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False)

    
    ids = [f"Request {req}" for req, resp in sessionControl_NRC12]
    @allure.severity('normal')
    @allure.title('物理寻址默认会话测试NRC12')
    @allure.description('验证物理寻址模式默认会话(0x01)下NRC12')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC12, ids=ids)
    def test_sessionControl_NRC12_Default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False)

    ids = [f"Request {req}" for req, resp in sessionControl_NRC12]
    @allure.severity('normal')
    @allure.title('物理寻址编程会话测试NRC12')
    @allure.description('验证物理寻址模式编程会话(0x02)下NRC12')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC12, ids=ids)
    def test_sessionControl_NRC12_Programming_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = [f"Request {req}" for req, resp in sessionControl_NRC12]
    @allure.severity('normal')
    @allure.title('物理寻址扩展会话测试NRC12')
    @allure.description('验证物理寻址模式扩展会话(0x03)下NRC12')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC12, ids=ids)
    def test_sessionControl_NRC12_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False)

    # @allure.severity('normal')
    # @allure.title('物理寻址默认会话测试NRC7E')
    # @allure.description('验证物理寻址模式默认会话(0x01)下NRC7E')
    # def test_sessionControl_NRC7E_Default_Phy(self, action, Driver):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '7F 10 7E', 1, iStep, False)

    # @allure.severity('normal')
    # @allure.title('物理寻址编程会话测试NRC7E')
    # @allure.description('验证物理寻址模式编程会话(0x02)下NRC7E')
    # def test_sessionControl_NRC7E_Programming_Phy(self, action, Driver):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '7F 10 7E', 2, iStep, False)

    # @allure.severity('minor')
    # @allure.title('物理寻址默认会话测试NRC22')
    # @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送会话切换请求(0x10 02)3. 预期返回NRC 0x22(条件不满足)4. 重置车速<3kph(2kph)''')
    # def test_sessionControl_NRC22_Programming_Phy(self, action, Driver):
    #     iStep = 1
    #     # 车速大于3kph
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '50 02 00 32 01 F4', 0, iStep, False)
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '7F 10 22', 0, iStep, False)
    #     # 车速小于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    # @allure.severity('minor')
    # @allure.title('物理寻址扩展会话测试NRC22')
    # @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送会话切换请求(0x10 02)3. 预期返回NRC 0x22(条件不满足)4. 重置车速<3kph(2kph)''')
    # def test_sessionControl_NRC22_Extended_Phy(self, action, Driver):
    #     iStep = 1
    #     # 车速大于3kph
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03 00 32 01 F4', 0, iStep, False)
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '7F 10 22', 0, iStep, False)
    #     # 车速小于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    # @allure.severity('minor')
    # @allure.title('物理寻址默认会话下NRC13 NRC22优先级测试')
    # @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送非法格式会话切换请求(0x10 02 00)3. 预期优先返回NRC 0x13(消息格式错误)4. 重置车速<3kph(2kph)''')
    # def test_sessionControl_NRC13andNRC22_Priority_Default_Phy(self, action, Driver):
    #     iStep = 1
    #     # 车速大于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02 00', '7F 10 13', 1, iStep, False)
    #     # 车速小于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    @allure.severity('minor')
    @allure.title('物理寻址默认会话下NRC13 NRC7E优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 02 00)2. 预期优先返回NRC 0x13(消息格式错误)''')
    def test_sessionControl_NRC13andNRC7E_Priority_Default_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02 00', '7F 10 13', 1, iStep, False)


    @allure.severity('minor')
    @allure.title('物理寻址扩展会话下NRC13 NRC22优先级测试')
    @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送非法格式会话切换请求(0x10 02 00)3. 预期优先返回NRC 0x13(消息格式错误)4. 重置车速<3kph(2kph)''')
    def test_sessionControl_NRC13andNRC22_Priority_Extended_Phy(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02 00', '7F 10 13', 3, iStep, False)
        # 车速小于3kph
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    @allure.severity('minor')
    @allure.title('物理寻址默认会话下NRC12 NRC13优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 05 00)2. 预期优先返回NRC 0x13(消息格式错误)''')
    def test_sessionControl_NRC12andNRC13_Priority_Default_Phy(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 05 00', '7F 10 12', 1, iStep, False)

    @allure.severity('minor')
    @allure.title('物理寻址编程会话下NRC12 NRC13优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 05 00)2. 预期优先返回NRC 0x13(消息格式错误)''')
    def test_sessionControl_NRC12andNRC13_Priority_Programming_Phy(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 05 00', '7F 10 12', 2, iStep, False)

    @allure.severity('minor')
    @allure.title('物理寻址扩展会话下NRC12 NRC13优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 05 00)2. 预期优先返回NRC 0x13(消息格式错误)''')
    def test_sessionControl_NRC12andNRC13_Priority_Extended_Phy(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 06 00', '7F 10 12', 3, iStep, False)



'''功能寻址测试用例'''
class Test_BOOT_SessionControl_Func(object):

    @allure.severity('normal')
    @allure.story('功能寻址会话管理')
    @allure.title('重复会话切换测试 [1003 → 1002] - 功能寻址')
    @allure.description('验证默认会话与编程会话的5次循环切换流程,测试系统在功能寻址模式下的会话稳定性')
    def test_sessionSwitch1_Func(self, action, Driver):
        iStep = 1
        for i in range(5):
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03 00 32 01 F4", 0, iStep, False, 'UDSFun')
            time.sleep(0.5)
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False, 'UDSFun')
            time.sleep(0.5)
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", "50 01 00 32 01 F4", 0, iStep, False, 'UDSFun')
            time.sleep(0.5)
            
    @allure.severity('normal')
    @allure.title('功能寻址会话切换测试 [1003 → 1002 → 1101]')
    @allure.description('''验证三级会话切换流程:1. 默认会话(1001) → 编程会话(1002) 2. 尝试在编程会话下进入诊断会话(1101) 3. 检查NRC33的预期响应''')
    def test_sessionSwitch2_Func(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03 00 32 01 F4", 0, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "11 01", "51 01", 0, iStep, False, 'UDSFun')

    @allure.severity('normal')
    @allure.title('功能寻址多级会话切换测试 [1003 → 1002 → 1103 → 1101]')
    @allure.description('''验证四级会话切换流程:1. 默认会话(1001) → 编程会话(1002) 2. 编程会话下尝试进入编程会话(1103) 3. 检查NRC33的安全访问拒绝响应 4. 验证返回默认会话(01101)的正响应''')
    def test_sessionSwitch3_Func(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03 00 32 01 F4", 0, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "11 03", "", 0, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "11 01", "51 01", 0, iStep, False)

    @allure.severity('normal')
    @allure.title('功能寻址复合场景测试 [1002 → 1002 → 重启 → 22F186]')
    @allure.description('''验证包含电源重启的完整会话流程:1. 编程会话(1002) → 编程会话(1002)2. 执行MRR硬件重启操作3. 等待系统重新初始化(4秒)4. 验证诊断服务0x22F186的正响应''')
    def test_sessionSwitch4_Func(self, action, Driver):
        iStep = 1
        for i in range(3):
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 03", "50 03 00 32 01 F4", 0, iStep, False, 'UDSFun')
            iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 02", "50 02 00 32 01 F4", 0, iStep, False)
            time.sleep(0.5)
            iStep = Driver['CAN'].restartETC_Power(Driver,iStep)
            with allure.step(f'Step{iStep}:wait 3s'): # type: ignore
                time.sleep(4)
                iStep += 1
            # iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, "22 F1 86", "62 F1 86 01", 0, iStep, False, 'UDSFun')

    ids = [f"Request {req}" for req, resp in sessionControl]
    @allure.severity('normal')
    @allure.title('功能寻址默认会话测试')
    @allure.description('验证功能寻址模式默认会话(0x01)测试')
    @pytest.mark.parametrize('req,resp', sessionControl, ids=ids)
    def test_sessionControl_Default_Func(self, action,  Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun')

    
    ids = [f"Request {req}" for req, resp in sessionControl]
    @allure.severity('normal')
    @allure.title('功能寻址编程会话测试')
    @allure.description('验证功能寻址模式编程会话(0x02)测试')
    @pytest.mark.parametrize('req,resp', sessionControl, ids=ids)
    def test_sessionControl_Programming_Func(self, action,  Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun')

    ids = [f"Request {req}" for req, resp in sessionControl]
    @allure.severity('normal')
    @allure.title('功能寻址扩展会话测试')
    @allure.description('验证功能寻址模式扩展会话(0x03)测试')
    @pytest.mark.parametrize('req,resp', sessionControl, ids=ids)
    def test_sessionControl_Extended_Func(self, action,  Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun')


    ids = [f"Request {req}" for req, resp in sessionControl_NRC13]
    @allure.severity('normal')
    @allure.title('功能寻址默认会话测试NRC13')
    @allure.description('验证功能寻址模式默认会话(0x01)下NRC13')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC13, ids=ids)
    def test_sessionControl_NRC13_Default_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun')

    ids = [f"Request {req}" for req, resp in sessionControl_NRC13]
    @allure.severity('normal')
    @allure.title('功能寻址编程会话测试NRC13')
    @allure.description('验证功能寻址模式编程会话(0x02)下NRC13')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC13, ids=ids)
    def test_sessionControl_NRC13_Programming_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun')

    ids = [f"Request {req}" for req, resp in sessionControl_NRC13]
    @allure.severity('normal')
    @allure.title('功能寻址扩展会话测试NRC13')
    @allure.description('验证功能寻址模式扩展会话(0x03)下NRC13')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC13, ids=ids)
    def test_sessionControl_NRC13_Extended_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun')

    
    ids = [f"Request {req}" for req, resp in sessionControl_NRC12]
    @allure.severity('normal')
    @allure.title('功能寻址默认会话测试NRC12')
    @allure.description('验证功能寻址模式默认会话(0x01)下NRC12')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC12, ids=ids)
    def test_sessionControl_NRC12_Default_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 1, iStep, False, 'UDSFun')

    ids = [f"Request {req}" for req, resp in sessionControl_NRC12]
    @allure.severity('normal')
    @allure.title('功能寻址编程会话测试NRC12')
    @allure.description('验证功能寻址模式编程会话(0x02)下NRC12')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC12, ids=ids)
    def test_sessionControl_NRC12_Programming_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun')

    ids = [f"Request {req}" for req, resp in sessionControl_NRC12]
    @allure.severity('normal')
    @allure.title('功能寻址扩展会话测试NRC12')
    @allure.description('验证功能寻址模式扩展会话(0x03)下NRC12')
    @pytest.mark.parametrize('req,resp', sessionControl_NRC12, ids=ids)
    def test_sessionControl_NRC12_Extended_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 3, iStep, False, 'UDSFun')

    
    # @allure.severity('normal')
    # @allure.title('功能寻址默认会话测试NRC7E')
    # @allure.description('验证功能寻址模式默认会话(0x01)下NRC7E')
    # def test_sessionControl_NRC7E_Default_Func(self, action, Driver):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '', 1, iStep, False, 'UDSFun')


    # @allure.severity('normal')
    # @allure.title('功能寻址编程会话测试NRC7E')
    # @allure.description('验证功能寻址模式编程会话(0x02)下NRC7E')
    # def test_sessionControl_NRC7E_Programming_Func(self, action, Driver):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '', 2, iStep, False, 'UDSFun')

    # @allure.severity('minor')
    # @allure.title('功能寻址默认会话测试NRC22')
    # @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送会话切换请求(0x10 02)3. 预期返回NRC 0x22(条件不满足)4. 重置车速<3kph(2kph)''')
    # def test_sessionControl_NRC22_Programming_Func(self, action, Driver):
    #     iStep = 1
    #     # 车速大于3kph
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '50 02 00 32 01 F4', 0, iStep, False, 'UDSFun')
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '7F 10 22', 0, iStep, False, 'UDSFun')
    #     # 车速小于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    # @allure.severity('minor')
    # @allure.title('功能寻址扩展会话测试NRC22')
    # @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送会话切换请求(0x10 02)3. 预期返回NRC 0x22(条件不满足)4. 重置车速<3kph(2kph)''')
    # def test_sessionControl_NRC22_Extended_Func(self, action, Driver):
    #     iStep = 1
    #     # 车速大于3kph
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03 00 32 01 F4', 0, iStep, False, 'UDSFun')
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02', '7F 10 22', 0, iStep, False, 'UDSFun')
    #     # 车速小于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    # @allure.severity('minor')
    # @allure.title('功能寻址默认会话下NRC13 NRC22优先级测试')
    # @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送非法格式会话切换请求(0x10 02 00)3. 预期优先返回NRC 0x13(消息格式错误)4. 重置车速<3kph(2kph)''')
    # def test_sessionControl_NRC13andNRC22_Priority_Default_Func(self, action, Driver):
    #     iStep = 1
    #     # 车速大于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02 00', '7F 10 13', 1, iStep, False, 'UDSFun')
    #     # 车速小于3kph
    #     iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    @allure.severity('minor')
    @allure.title('功能寻址默认会话下NRC13 NRC7E优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 02 00)2. 预期优先返回NRC 0x13(消息格式错误)''')
    def test_sessionControl_NRC13andNRC7E_Priority_Default_Func(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02 00', '7F 10 13', 1, iStep, False, 'UDSFun')


    @allure.severity('minor')
    @allure.title('功能寻址扩展会话下NRC13 NRC22优先级测试')
    @allure.description('''验证条件优先级:1. 设置车速>3kph(8kph)2. 发送非法格式会话切换请求(0x10 02 00)3. 预期优先返回NRC 0x13(消息格式错误)4. 重置车速<3kph(2kph)''')
    def test_sessionControl_NRC13andNRC22_Priority_Extended_Func(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 8)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 02 00', '7F 10 13', 3, iStep, False, 'UDSFun')
        # 车速小于3kph
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)

    @allure.severity('minor')
    @allure.title('功能寻址默认会话下NRC12 NRC13优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 05 00)2. 预期优先返回无响应(NRC12)''')
    def test_sessionControl_NRC12andNRC13_Priority_Default_Func(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 05 00', '', 1, iStep, False, 'UDSFun')

    @allure.severity('minor')
    @allure.title('功能寻址编程会话下NRC12 NRC13优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 05 00)2. 预期优先返回无响应 (NRC 0x12)''')
    def test_sessionControl_NRC12andNRC13_Priority_Programming_Func(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 05 00', '', 2, iStep, False, 'UDSFun')

    @allure.severity('minor')
    @allure.title('功能寻址扩展会话下NRC12 NRC13优先级测试')
    @allure.description('''验证条件优先级:1. 发送非法格式会话切换请求(0x10 05 00)2. 预期优先返回NRC 0x13(消息格式错误)''')
    def test_sessionControl_NRC12andNRC13_Priority_Extended_Func(self, action, Driver):
        iStep = 1
        # 车速大于3kph
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 06 00', '', 3, iStep, False, 'UDSFun')